home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / afloat.zip / ITOF.ASM < prev    next >
Assembly Source File  |  1988-03-14  |  1KB  |  72 lines

  1.         PAGE ,132
  2. ;----------------------------------------------------------
  3. ; ITOF -- version for use with assembly language programs
  4. ;
  5. ; Copyright Bob Kline 1988
  6. ;
  7. ; Purpose:
  8. ;       Convert two-byte integer to floating point value
  9. ;
  10. ; Input:
  11. ;       AX holds integer to be converted
  12. ;
  13. ; Output:
  14. ;       4-byte real stored in DX:AX
  15. ;
  16. ; Other registers used:
  17. ;       CX
  18. ;
  19. ; Other procedures called:
  20. ;       none
  21. ;----------------------------------------------------------
  22.         PUBLIC  ITOF
  23.  
  24.     .MODEL    SMALL
  25.  
  26.     .CODE
  27.  
  28. ITOF    PROC
  29.  
  30. ; prepare CX for sign and check for (integer == 0)
  31.         XOR     CX,CX
  32.         OR      AX,AX
  33.         JNZ     SAVE_SIGN
  34.         XOR     DX,DX
  35.         RET
  36.  
  37. SAVE_SIGN:
  38.         JNS     POSITIVE
  39.         NEG     AX
  40.         OR      CH,80h
  41. POSITIVE:
  42.         PUSH    CX
  43.  
  44. ; use BX for mantissa, starting out with 23
  45.         MOV     CX,23
  46.  
  47. ; shift left until we get a one bit in the
  48. ;   23rd position from the right
  49.         XOR     DX,DX
  50. MORE:   SHL     AX,1
  51.         RCL     DX,1
  52.         DEC     CX
  53.         TEST    DX,80h
  54.         JZ      MORE
  55.         AND     DX,7Fh
  56.  
  57. ; bias the exponent and fold it in
  58.         ADD     CX,127
  59.         XCHG    CH,CL
  60.         SHR     CX,1
  61.         OR      DX,CX
  62.  
  63. ; get the sign back off the stack fold it in, and we're done
  64.     POP    CX
  65.         OR      DX,CX
  66.  
  67.         RET
  68.  
  69. ITOF   ENDP
  70.  
  71.         END
  72.